package com.example.demo1.controller;

import com.example.demo1.dao.UserDAO;
import com.example.demo1.entity.JsonResult;
import com.example.demo1.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * @author zhw
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserDAO userDAO;


    @RequestMapping("/findAll")
    public JsonResult<List> findAll() {
        List<User> list = userDAO.findAll();
        return new JsonResult<>(list, "200", "操作成功");
    }

    @RequestMapping("/findOne")
    public JsonResult<User> findOne(@RequestParam Long id) {
        User user = userDAO.findOne(id);
        return new JsonResult<>(user, "200", "操作成功");
    }

    @PostMapping("/findByCreateTime")
    public JsonResult<List> findByCreateTime(@RequestParam Date beforeTime, @RequestParam Date afterTime) {
        List<User> list = userDAO.findByCreateTime(beforeTime,afterTime);
        return new JsonResult<>(list, "200", "操作成功");
    }

}
